<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="车牌号">
              <a-input placeholder="请输入车牌号" v-model="queryParam.plate"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="车架号">
              <a-input placeholder="请输入车架号" v-model="queryParam.vin"></a-input>
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="报价状态">
              <a-select :size="size" default-value="a1" style="width: 200px" v-model="queryParam.bjdstatus">
                <a-select-option key="0">未报价</a-select-option>
                <a-select-option key="1">已报价</a-select-option>
                <a-select-option key="2">已下订单</a-select-option>
                <a-select-option key="3">显示全部</a-select-option>
              </a-select>
            </a-form-item>
          </a-col> -->
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="事故号">
                <a-input placeholder="请输入事故号" v-model="queryParam.accidentNumber"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handlegeneratequo" type="primary" icon="plus">报价</a-button> -->
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"></j-super-query>
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" bordered rowKey="id" class="j-table-force-nowrap" :scroll="{ x: true }"
        :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, selectedRows: selectedRows, onChange: onSelectChange, type: 'radio' }"
        @change="handleTableChange">
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="imgsSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <span v-else="text.indexOf(',') < 0">
            <img :src="getImgView(text)" :preview="record.id" height="25px" alt=""
              style="max-width:80px;font-size: 12px;font-style: italic;" />
          </span>
          <span v-else="text.indexOf(',') > 0">
            <span v-for="(srcTex, index) in (text.spilt(','))">
              <img :src="getImgView(srcTex)" :preview="record.id" height="25px" alt=""
                style="max-width:80px;font-size: 12px;font-style: italic;" />
            </span>
          </span>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="quoPriceSlot" slot-scope="text, record">
          <div>
            <a-input-number v-model="record.quoprice"></a-input-number>
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">比价</a>
          <a-divider type="vertical" />
          <!-- <a @click="handleViewQuo(record)">查看报价</a> -->
        </span>

      </a-table>
    </div>
    <scmxjd-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>
  
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import '@/assets/less/TableExpand.less'
import { ajaxGetDictItems, getDictItemsFromCache } from '@/api/api';
import { postAction } from '../../../../api/manage';
import ScmxjdModal from './comparequomodules/ScmxjdModal'
export default {
  name: 'comparequolist',
  mixins: [JeecgListMixin],
  components: {
    ScmxjdModal
  },
  data () {
    return {
      description: '供应商报价平台',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '询价单号',
          align: 'center',
          dataIndex: 'billcode',
        },
        {
          title: '车辆',
          align: 'center',
          dataIndex: 'vehicle',
        },
        {
          title: "车架号",
          align: "center",
          dataIndex: "vin"
        },
        {
          title: "车牌号",
          align: "center",
          dataIndex: "plate"
        },
        {
          title: "行驶证",
          align: "center",
          dataIndex: "licenseimageString",
          scopedSlots: {
            customRender: 'imgSlot'
          }
        },
        {
          title: '事故图片',
          align: "center",
          dataIndex: "accidentimagesString",
          scopedSlots: {
            customRender: 'imgSlot'
          }
        },
        {
          title: '配件数量',
          align: 'center',
          dataIndex: 'partcount'
        },
        // {
        //   title: '状态',
        //   align: "center",
        //   dataIndex: 'quostate'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
        // {
        //   title: '报价单价',
        //   align: "center",
        //   width: '200px',
        //   dataIndex: 'quoprice',
        //   scopedSlots: {
        //     customRender: 'quoPriceSlot'
        //   }
        // },
        //   {
        //     title:'报价总价',
        //     align:'center',
        //     dataIndex:"quovalue",
        //     width:'200px',
        //     scopedSlots:{
        //         customRender:"quovalueSlot"
        //     }
        //   }
      ],
      selectedRows: [],
      url: {
        list: '/rfq.xbj/scmxjd/getwxdjvendorlistinfo',
        generateQuoUrl: '/rfq.quo/scmquotation/generatequo'
      },
      xjdmodel: {},
      dictOptions: {},
      superFieldList: [],
      quanlityOptions: [],
      xjdquovisable: false,
    }
  },
  async created () {
    //获取配件品质
    let dictCode = await getDictItemsFromCache('pjpz');
    this.quanlityOptions = dictCode;
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    handlequo (record) {
      if (record.quostate === '已报价') {
        this.$message.error("当前询价单已报价，不允许重复报价");
        return;
      }
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "报价";
      this.$refs.modalForm.disableSubmit = true;
    },
    handleViewQuo (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "查看报价";
      this.$refs.modalForm.disableSubmit = true;

    },
    handlegeneratequo () {
      this.xjdquovisable = true;
      // if (this.selectedRows.length == 0) {
      //   this.$message.error("请选择询价进行报价");
      //   return;
      // }
      // let ids = [];
      // for (let i = 0; i < this.selectedRows.length; i++) {
      //   ids.push({
      //     itemid: this.selectedRows[i].itemid,
      //     quoprice: this.selectedRows[i].quoprice,
      //     vendorid: this.selectedRows[i].vendorid
      //   })
      // }
      // postAction(this.url.generateQuoUrl, { id: ids }).then(res => {
      //   if (res.success) {
      //     this.$message.success("生成报价单成功！");
      //     this.loadData();
      //     return;
      //   } else {
      //     this.$message.error(res.message);
      //     return;
      //   }
      // })
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    initDictConfig () { },
    getSuperFieldList () {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'createBy', text: '创建人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期' })
      fieldList.push({ type: 'pca', value: 'cityid', text: '城市' })
      fieldList.push({ type: 'pca', value: 'regionid', text: '地区' })
      fieldList.push({ type: 'string', value: 'vehicle', text: '车辆信息', dictCode: '' })
      fieldList.push({ type: 'string', value: 'plate', text: '车牌号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'vin', text: '车架号', dictCode: '' })
      fieldList.push({ type: 'Blob', value: 'licenseimage', text: '行车证图片', dictCode: '' })
      fieldList.push({ type: 'string', value: 'accidentNumber', text: '事故号', dictCode: '' })
      fieldList.push({ type: 'Blob', value: 'accidentimages', text: '事故图片', dictCode: '' })
      fieldList.push({ type: 'string', value: 'status', text: '单据状态', dictCode: '' })
      fieldList.push({ type: 'string', value: 'auditstatus', text: '审核状态', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'partcount', text: '配件数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'bah', text: '报案号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xlcaddress', text: '修理厂地址', dictCode: '' })
      fieldList.push({ type: 'string', value: 'xlclink', text: '修理厂联系方式', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
  